<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>GDB调试基础使用方法 | 王竹兴 | Blob</title>
  <meta name="description" content="概述 ​	GDB(GNU Debugger) 是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 ​	参考: gdb调试利器  进入GDB环境调试  加载编译选项” –g” 以便在GDB调试环境中能够显示出具体的错误位置。 例： 1g++ filename.cpp –g –o filename 在cmake编译中，可以通过可选项 -DCMAKE_">
<meta name="keywords" content="Debug">
<meta property="og:type" content="article">
<meta property="og:title" content="GDB调试基础使用方法">
<meta property="og:url" content="http://zhulao.gitee.io/blog/2019/02/20/GDB调试基础使用方法/index.html">
<meta property="og:site_name" content="王竹兴 | Blog">
<meta property="og:description" content="概述 ​	GDB(GNU Debugger) 是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 ​	参考: gdb调试利器  进入GDB环境调试  加载编译选项” –g” 以便在GDB调试环境中能够显示出具体的错误位置。 例： 1g++ filename.cpp –g –o filename 在cmake编译中，可以通过可选项 -DCMAKE_">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-04-27T14:16:22.492Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="GDB调试基础使用方法">
<meta name="twitter:description" content="概述 ​	GDB(GNU Debugger) 是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。 ​	参考: gdb调试利器  进入GDB环境调试  加载编译选项” –g” 以便在GDB调试环境中能够显示出具体的错误位置。 例： 1g++ filename.cpp –g –o filename 在cmake编译中，可以通过可选项 -DCMAKE_">
  <!-- Canonical links -->
  <link rel="canonical" href="http://zhulao.gitee.io/blog/2019/02/20/GDB调试基础使用方法/index.html">
  
    <link rel="alternate" href="/atom.xml" title="王竹兴 | Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  
  
  
  
</head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/wzx3" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpeg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">王竹兴</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md"></h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> XiaMen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索">
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech>
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>人生最快意的事情之一, 就是你比别人牛逼, 然后静静的看别人在你面前装逼。</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/便签/">便签</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/教程/">教程</a><span class="category-list-count">22</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/游记/">游记</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/随笔/">随笔</a><span class="category-list-count">6</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/DL/" style="font-size: 13.25px;">DL</a> <a href="/blog/tags/Debug/" style="font-size: 13.5px;">Debug</a> <a href="/blog/tags/Doc/" style="font-size: 13px;">Doc</a> <a href="/blog/tags/Hexo/" style="font-size: 13.25px;">Hexo</a> <a href="/blog/tags/Links/" style="font-size: 13px;">Links</a> <a href="/blog/tags/Linux/" style="font-size: 13.25px;">Linux</a> <a href="/blog/tags/Mac/" style="font-size: 13px;">Mac</a> <a href="/blog/tags/bazel/" style="font-size: 13px;">bazel</a> <a href="/blog/tags/c-c/" style="font-size: 13.75px;">c/c++</a> <a href="/blog/tags/git/" style="font-size: 13px;">git</a> <a href="/blog/tags/rst/" style="font-size: 13px;">rst</a> <a href="/blog/tags/scripts/" style="font-size: 13.75px;">scripts</a> <a href="/blog/tags/ssh/" style="font-size: 13px;">ssh</a> <a href="/blog/tags/国学经典/" style="font-size: 13px;">国学经典</a> <a href="/blog/tags/持续集成/" style="font-size: 13.25px;">持续集成</a> <a href="/blog/tags/科幻小说/" style="font-size: 14px;">科幻小说</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/05/">五月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/04/">四月 2019</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/03/">三月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/02/">二月 2019</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/26/读论语/" class="title">读论语</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-26T01:45:07.000Z" itemprop="datePublished">2019-05-26</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读变型战争/" class="title">读变型战争</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:51:57.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读星际远征/" class="title">读黑客横行</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:40:09.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/15/代码格式化工具-clang-format/" class="title">代码格式化工具:clang-format</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-15T14:39:51.000Z" itemprop="datePublished">2019-05-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/12/Linux-疑难杂症/" class="title">Linux 疑难杂症</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-12T02:50:29.000Z" itemprop="datePublished">2019-05-12</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#进入gdb环境调试"><span class="toc-number">1.</span> <span class="toc-text"> 进入GDB环境调试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#加载编译选项-g"><span class="toc-number">1.1.</span> <span class="toc-text"> 加载编译选项” –g”</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#加载可执行文件到gdb中"><span class="toc-number">1.2.</span> <span class="toc-text"> 加载可执行文件到GDB中</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#对执行文件进行输入参数的设置"><span class="toc-number">1.3.</span> <span class="toc-text"> 对执行文件进行输入参数的设置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#gdb内使用make"><span class="toc-number">1.4.</span> <span class="toc-text"> GDB内使用make</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#文件执行"><span class="toc-number">1.5.</span> <span class="toc-text"> 文件执行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#退出gdb调试环境"><span class="toc-number">1.6.</span> <span class="toc-text"> 退出GDB调试环境</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#断点设置"><span class="toc-number">2.</span> <span class="toc-text"> 断点设置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#断点设置的方法"><span class="toc-number">2.1.</span> <span class="toc-text"> 断点设置的方法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#条件断点"><span class="toc-number">2.2.</span> <span class="toc-text"> 条件断点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#断点条件更改"><span class="toc-number">2.3.</span> <span class="toc-text"> 断点条件更改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#断点信息查看"><span class="toc-number">2.4.</span> <span class="toc-text"> 断点信息查看</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#断点的使能"><span class="toc-number">2.5.</span> <span class="toc-text"> 断点的使能</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#调试的方式"><span class="toc-number">3.</span> <span class="toc-text"> 调试的方式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#打印变量-p"><span class="toc-number">3.1.</span> <span class="toc-text"> 打印变量 p</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#单步调试-s"><span class="toc-number">3.2.</span> <span class="toc-text"> 单步调试 s</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#单步执行-n"><span class="toc-number">3.3.</span> <span class="toc-text"> 单步执行 n</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#继续执行-c"><span class="toc-number">3.4.</span> <span class="toc-text"> 继续执行 c</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#执行完当前函数并打印出信息-finish"><span class="toc-number">3.5.</span> <span class="toc-text"> 执行完当前函数并打印出信息 finish</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#设置变量值调试"><span class="toc-number">3.6.</span> <span class="toc-text"> 设置变量值调试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#段错误的查找"><span class="toc-number">4.</span> <span class="toc-text"> 段错误的查找</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#段回溯-bt"><span class="toc-number">4.1.</span> <span class="toc-text"> 段回溯 bt</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#进入错误段"><span class="toc-number">4.2.</span> <span class="toc-text"> 进入错误段</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#代码显示"><span class="toc-number">4.3.</span> <span class="toc-text"> 代码显示</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-GDB调试基础使用方法" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      GDB调试基础使用方法
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/02/20/GDB调试基础使用方法/" class="article-date">
	  <time datetime="2019-02-20T04:52:09.000Z" itemprop="datePublished">2019-02-20</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/教程/">教程</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/Debug/">Debug</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/02/20/GDB调试基础使用方法/#comments" class="article-comment-link">评论</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 1,061(字)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 4(分)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <p><strong>概述</strong></p>
<p>​	<strong>GDB(GNU Debugger)</strong> 是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。</p>
<p>​	参考: <a href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html" target="_blank" rel="noopener">gdb调试利器</a></p>
<h2 id="进入gdb环境调试"><a class="markdownIt-Anchor" href="#进入gdb环境调试"></a> 进入GDB环境调试</h2>
<h3 id="加载编译选项-g"><a class="markdownIt-Anchor" href="#加载编译选项-g"></a> 加载编译选项” –g”</h3>
<p>以便在GDB调试环境中能够显示出具体的错误位置。</p>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">g++ filename.cpp –g –o filename</span><br></pre></td></tr></table></figure>
<p>在cmake编译中，可以通过可选项 <code>-DCMAKE_VERBOSE_MAKEFILE=1</code>  ,具体显示编译过程，保证-g选项在编译过程中使用。</p>
<h3 id="加载可执行文件到gdb中"><a class="markdownIt-Anchor" href="#加载可执行文件到gdb中"></a> 加载可执行文件到GDB中</h3>
<p>在执行文件所在文件夹里，使用 <code>gdb</code> 命令进入到GDB调试环境中。之后使用 <code>file filename</code><br>
或者使用 <code>gdb filename</code> （filename可执行文件名）。</p>
<h3 id="对执行文件进行输入参数的设置"><a class="markdownIt-Anchor" href="#对执行文件进行输入参数的设置"></a> 对执行文件进行输入参数的设置</h3>
<p>使用命令 <code>set args parameter</code> (parameter为输入的参数)，加载运行所需的参数。通过 <code>show args</code> 查看加载参数的情况。</p>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set args /home/hello.png 2016 12</span><br></pre></td></tr></table></figure>
<p>使用’show args’后:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/home/hello.png 2016 12</span><br></pre></td></tr></table></figure>
<h3 id="gdb内使用make"><a class="markdownIt-Anchor" href="#gdb内使用make"></a> GDB内使用make</h3>
<p>外部文件有修改的情况下，直接在GDB环境中使用“make”进行编译。</p>
<h3 id="文件执行"><a class="markdownIt-Anchor" href="#文件执行"></a> 文件执行</h3>
<p>使用 <code>r</code> 即可对文件进行执行。</p>
<h3 id="退出gdb调试环境"><a class="markdownIt-Anchor" href="#退出gdb调试环境"></a> 退出GDB调试环境</h3>
<p>使用 <code>q</code> 退出调试环境。</p>
<h2 id="断点设置"><a class="markdownIt-Anchor" href="#断点设置"></a> 断点设置</h2>
<h3 id="断点设置的方法"><a class="markdownIt-Anchor" href="#断点设置的方法"></a> 断点设置的方法</h3>
<ul>
<li>使用行号：<code>b linenumber</code> 例：“b 2017”</li>
<li>使用函数名 <code>b function</code>   例：“b hello”</li>
<li>使用地址 <code>b *address</code>    例：“b *0x404”</li>
</ul>
<blockquote>
<p>若在不同文件上打断点，在行号或函数名前加上文件名和冒号“filename:”。</p>
</blockquote>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">b hello.cpp:hello </span><br><span class="line">b hello.cpp:2017</span><br></pre></td></tr></table></figure>
<h3 id="条件断点"><a class="markdownIt-Anchor" href="#条件断点"></a> 条件断点</h3>
<p>在1小点方法后面加入条件，断点在条件成立时起停止作用。</p>
<p>例:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">b 12 if x &gt; y  // 在x &gt; y情况下，断点起作用。</span><br></pre></td></tr></table></figure>
<h3 id="断点条件更改"><a class="markdownIt-Anchor" href="#断点条件更改"></a> 断点条件更改</h3>
<p>将指定断点号的条件进行修改:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">condition breakpointnumber expression</span><br></pre></td></tr></table></figure>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">condition 12 if x = y</span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>condition breakpointnumber</code> 停止使用条件，断点不受条件限制使用。</p>
</blockquote>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">condition 12</span><br></pre></td></tr></table></figure>
<h3 id="断点信息查看"><a class="markdownIt-Anchor" href="#断点信息查看"></a> 断点信息查看</h3>
<ul>
<li>查看所有的断点信息: <code>info b</code></li>
<li>查看指定断点号断点信息: <code>info b number</code></li>
</ul>
<h3 id="断点的使能"><a class="markdownIt-Anchor" href="#断点的使能"></a> 断点的使能</h3>
<ul>
<li>停止该号断点。但未删除: <code>dis breakpointnumber</code></li>
<li>使能改号断点: <code>enable breakpointnumber</code></li>
</ul>
<h2 id="调试的方式"><a class="markdownIt-Anchor" href="#调试的方式"></a> 调试的方式</h2>
<h3 id="打印变量-p"><a class="markdownIt-Anchor" href="#打印变量-p"></a> 打印变量 <code>p</code></h3>
<ul>
<li>打印变量值：<code>p variable</code> 例: “p x”</li>
<li>打印变量地址：<code>p &amp;variable</code> 例: “p &amp;x”</li>
<li>打印指针内容：<code>p *point</code>  例: “p *pData”</li>
</ul>
<h3 id="单步调试-s"><a class="markdownIt-Anchor" href="#单步调试-s"></a> 单步调试 <code>s</code></h3>
<p>类似于 <strong>step in</strong></p>
<ul>
<li>单步执行，遇到函数，进入到函数内部执行。<br>
<code>s number</code> 进行多步执行</li>
</ul>
<h3 id="单步执行-n"><a class="markdownIt-Anchor" href="#单步执行-n"></a> 单步执行 <code>n</code></h3>
<p>类似 <strong>step over</strong> 执行，遇到函数，不进入函数内部，直接执行完函数。</p>
<p>​	<code>n number</code> 进行多步执行</p>
<h3 id="继续执行-c"><a class="markdownIt-Anchor" href="#继续执行-c"></a> 继续执行 <code>c</code></h3>
<p>在程序在执行中遇到断点后，使用 <code>c</code> 继续执行</p>
<h3 id="执行完当前函数并打印出信息-finish"><a class="markdownIt-Anchor" href="#执行完当前函数并打印出信息-finish"></a> 执行完当前函数并打印出信息 <code>finish</code></h3>
<p>在函数内部使用 <code>finish</code> ，执行完当前整个函数打印返回信息</p>
<h3 id="设置变量值调试"><a class="markdownIt-Anchor" href="#设置变量值调试"></a> 设置变量值调试</h3>
<p><code>set var variable = x</code> 将变量设置为x后进行调试</p>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set var tmp = 5</span><br></pre></td></tr></table></figure>
<p>将变量 tmp 设置为5，var关键词确保不产生冲突</p>
<h2 id="段错误的查找"><a class="markdownIt-Anchor" href="#段错误的查找"></a> 段错误的查找</h2>
<h3 id="段回溯-bt"><a class="markdownIt-Anchor" href="#段回溯-bt"></a> 段回溯 <code>bt</code></h3>
<ul>
<li>在出现 segment fault 时，使用命令进行段错误的查看。</li>
<li>可以得到错误坐在的函数。像得到某人家庭地址。</li>
<li>也可使用 <code>where</code></li>
</ul>
<h3 id="进入错误段"><a class="markdownIt-Anchor" href="#进入错误段"></a> 进入错误段</h3>
<ul>
<li>在查看到错误的位置之后，使用 <code>frame number</code> 进入到该段内部。</li>
<li>进入内部之后便可以进行局部变量的打印调试。</li>
</ul>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">frame 5</span><br></pre></td></tr></table></figure>
<p>就进入到段5.</p>
<ul>
<li>切换到上一层段: <code>up</code></li>
<li>切换到下一层段: <code>down</code></li>
</ul>
<h3 id="代码显示"><a class="markdownIt-Anchor" href="#代码显示"></a> 代码显示</h3>
<ul>
<li>显示当前代码: <code>l</code></li>
<li>显示当前之前的代码: <code>l -</code></li>
<li>显示该行周围代码: <code>l number</code></li>
<li>显示该函数周围代码: <code>l function</code> （C++代码需要在函数名前加类名，重载函数需要在函数内加参数类型）</li>
<li>显示指定文件指定行周围代码: <code>l filename:linenumber</code></li>
</ul>
<p>例:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">l hello.cpp:1   // 从hello.cpp第一行开始显示</span><br></pre></td></tr></table></figure>
<ul>
<li>显示指定文件指定函数周围代码: <code>l filename:function</code></li>
</ul>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">l hello.cpp:Util::hello    // 显示hello.cpp文件下，Util类的函数hello</span><br></pre></td></tr></table></figure>
<ul>
<li>显示起始终止行内代码: <code>l fisrt,last</code></li>
</ul>
<p>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">l 1,30  // 从第0行显示到第30行的内容</span><br></pre></td></tr></table></figure>
      
    </div>
    <div class="article-footer">
      <!-- <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://zhulao.gitee.io/blog/2019/02/20/GDB调试基础使用方法/" title="GDB调试基础使用方法" target="_blank" rel="external">http://zhulao.gitee.io/blog/2019/02/20/GDB调试基础使用方法/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/wzx3" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpeg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/wzx3" target="_blank"><span class="text-dark">王竹兴</span><small class="ml-1x"></small></a></h3>
        <div></div>
      </div>
    </figure>
  </div>
</div>
 -->

    </div>
  </article>
  
    
  <section id="comments">
  	
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/02/20/SSH基础使用方法/" title="SSH基础使用方法"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/02/20/Git基础使用方法/" title="Git基础使用方法"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/blog/js/plugin.min.js"></script>
<script src="/blog/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/blog/js/insight.js"></script>





   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   






</body>
</html>